

#include "authorization_in_app.h"
#include "first_title.h"

static lv_timer_t * timer  = NULL;

static void wait_auth_timer(lv_timer_t * timer)
{
    // //debug_d("wait_auth_timer----1\n");
    // if(pt_accredit_tokenpwd_get()) //pt_accredit_token_get()&&
    // {
    //     //debug_d("wait_auth_timer----2\n");
    //     //if(pt_user_agreement_get())
    //     {
    //         debug_d("---enter page:home \n");
    //         com_title_create();
    //         root_page_enter_home(LOAD_ANIM_NONE);
    //     }
    //     // else
    //     // {
    //     //     debug_d("---enter page:user_agreement \n");
    //     //     page_install("user_agreement",lv_page_user_agreement_create(),NULL);
    //     //     page_push_anim("user_agreement",LOAD_ANIM_MOVE_LEFT);
    //     //     first_title_create();
    //     // }
    // }

    // if(pt_auth_cancle_get())
    // {
    //     pt_auth_cancle_set(0);
    //     debug_d("rcv auth cancle flag\n");

    //     page_install("link_fail",lv_page_linked_network_fail_create(),NULL);
    //     page_push_anim("link_fail",LOAD_ANIM_MOVE_LEFT);
    // }

}


void ui_init_authorization_in_app_page_src(lv_obj_t *superview)
{
    first_title_set(FIRST_PAGE_HIGH, 0, 0);

    lv_obj_t * img = lv_img_create(superview);
    midea_ui_set_img_src( img, pt_fs_get("MideaAPP.png"));
    midea_ui_safe_obj_align( img,LV_ALIGN_TOP_LEFT,127,104);

    lv_obj_t * img2 = lv_img_create(superview);
    midea_ui_set_img_src( img2, pt_fs_get("Correlation.png"));
    midea_ui_safe_obj_align( img2,LV_ALIGN_TOP_LEFT,230,127);

    lv_obj_t * img3 = lv_img_create(superview);
    midea_ui_set_img_src( img3, pt_fs_get("Device.png"));
    midea_ui_safe_obj_align( img3,LV_ALIGN_TOP_LEFT,267,80);

    lv_obj_t * label = lv_label_create(superview);
    lv_obj_set_style_text_font( label, lv_font_get(20), LV_STATE_DEFAULT );
    lv_obj_set_style_text_color(label,lv_color_make(0xff,0xff,0xff),LV_PART_MAIN);
    lv_obj_set_style_text_opa(label,LV_OPA_80,0);
    lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER,0);
    midea_ui_safe_set_text( label, "请前往美的美居App-面板设置页授权\n并管理美的美居下的设备及场景");
    midea_ui_safe_obj_align( label, LV_ALIGN_BOTTOM_MID,0,-50);

    timer = lv_timer_create(wait_auth_timer, 1000,  NULL);
}

static void authorization_page_on_custom_attr_config(page_base_t* self)
{
    
    return ;
}
static void authorization_page_on_view_load(page_base_t* self)
{
    ui_init_authorization_in_app_page_src(self->root);
    return ;
}
static void authorization_page_on_view_did_load(page_base_t* self)
{
    return ;
}
static void authorization_page_on_view_will_appear(page_base_t* self)
{
    return ;
}
static void authorization_page_on_view_did_appear(page_base_t* self)
{
    return ;
}
static void authorization_page_on_view_will_disappear(page_base_t* self)
{
    return ;
}
static void authorization_page_on_view_did_disappear(page_base_t* self)
{
    return ;
}
static void authorization_page_on_view_did_unload(page_base_t* self)
{
    if(timer){
        midea_ui_safe_del_timer(timer);
        timer = NULL;
    }
    return ;
}

static page_vtable_t page_param = {
    .on_custom_attr_config  = authorization_page_on_custom_attr_config,
    .on_view_load           = authorization_page_on_view_load,
    .on_view_did_load       = authorization_page_on_view_did_load,
    .on_view_will_appear    = authorization_page_on_view_will_appear,
    .on_view_did_appear     = authorization_page_on_view_did_appear,
    .on_view_will_disappear = authorization_page_on_view_will_disappear,
    .on_view_did_disappear  = authorization_page_on_view_did_disappear,
    .on_view_did_unload     = authorization_page_on_view_did_unload,
};


page_vtable_t* lv_page_authorization_in_app_create(void)
{
    return &page_param;
}
